<template>
	<view class="box">
		<view class="content">
			<view class="flex_wrap row_center">
				<u-image
					src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/25/c61f6633bd394bfba8c1ab7c545a3dee.png"
					width="124rpx" height="124rpx" mode="widthFix" />
			</view>
			<view>
				<u-text :text="detailInfo.favorableTitle" size="56rpx" color="#FF3C3C" align="center" margin="42rpx 0 18rpx" />
				<u-text :text="detailInfo.favorableDescription" size="28rpx" color="#3D3D3D" align="center" />
				<u-text :text="`有效期限至` +  $u.timeFormat(detailInfo.useTimeEnd, 'yyyy.mm.dd')" size="28rpx" color="#666" align="center" margin="16rpx 0 48rpx" />
			</view>
			<view class="">
				<u-button
					:text="btnTypes == 1 ? ('发送' + couponNum + '个红包') : ('发送' + couponNum + '张') "
					shape="circle"
					border="none"
					color="linear-gradient(90deg, #FF6E45 0%, #FE5037 100%)"
					openType="share"
				/>
			</view>
		</view>
	</view>
</template>

<script>
	import { baseUrl } from "@/config/tendIdConfig"
	import { favorableDetail,transfer} from "@/api/coupon.js";
	import { getFavorableInfoById ,shareFavorableType} from "@/api/order.js";
	export default {
		data() {
			return {
				couponNum:'',
				ledId:'',
				detailInfo:'',
				receiveId:'',
				btnTypes:'',
				checkedOnline:''
			};
		},
		onLoad(options) {
			this.couponNum = options.couponNum
			this.ledId = options.ledId
			this.btnTypes = options.btnTypes
			this.checkedOnline = options.checkedOnline || ''
			this.getCouponDetail(this.ledId)
		},
		methods: {
			getCouponDetail(ledId){
				getFavorableInfoById(ledId).then((res) => {
					if (res.code === 200 && res.data) {
					   this.detailInfo = res.data
					}
				});
			},
			
			//发送给朋友
			async onShareAppMessage(res) {
				await transfer({
				   favorableLedId: this.ledId,
				   number: this.couponNum,
				   source: this.checkedOnline == 1 ? 3 : 2,
				})
				    .then(async (res) => {
				        this.receiveId = res.data
						console.log(res,this.receiveId,'this.receiveId>>>')
				    })
				    .catch((error) => {
				        uni.$u.toast(error);
				    });
				return {
				    title: "HI!我向您赠送了一份优惠券！快去领取吧~",
				    path:
				        "pages_coupon/myShareReceive/index?favorableId=" +this.receiveId,
				};
				console.log(path,'this.path>>>')
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #1E2137;
	}

	.box {
		padding: 32rpx 28rpx;
	}

	.content {
		background: #fff;
		width: 100%;
		border-radius: 12rpx;
		padding: 64rpx 48rpx ;
	}
	
</style>